<html><head>
  <title>:nth-last-child() pseudo-class</title>
  <style type="text/css">.red { background-color : red }
ul > li:nth-last-child(odd) { background-color : green }
ol > li:nth-last-child(even) { background-color : green }
table.t1 tr:nth-last-child(-n+4) { background-color : green }
table.t2 td:nth-last-child(3n+1) { background-color : green }</style>
  <link rel="author" title="Daniel Glazman" href="http://glazman.org/">
  <link rel="author" title="Ian Hickson" href="mailto:ian@hixie.ch">
  <link rel="help" href="https://www.w3.org/TR/css3-selectors/#selectors"> <!-- bogus link to make sure it gets found -->
  <meta name="flags" content="">
 </head>
 <body>
<ul>
  <li>First list item</li>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This second list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
  <li>Third list item</li>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This fourth list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
  <li>Fifth list item</li>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This sixth list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
</ul>
<ol>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This first list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
  <li>Second list item</li>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This third list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
  <li>Fourth list item</li>
  <!--[ELEMENT('.red')]--><li class="red"><!--[TEXT('.red')]-->This fifth list item should have a green background<!--[/TEXT('.red')]--></li><!--[/ELEMENT('.red')]-->
  <li>Sixth list item</li>
</ol>
<div>
<table border="1" class="t1">
  <tbody><tr>
<td>1.1</td>
<td>1.2</td>
     <td>1.3</td>
</tr>
  <tr>
<td>2.1</td>
<td>2.2</td>
     <td>2.3</td>
</tr>
  <!--[ELEMENT('.red')]--><tr class="red"><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->Green row : 3.1<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->3.2<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
     <!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->3.3<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--></tr><!--[/ELEMENT('.red')]-->
  <!--[ELEMENT('.red')]--><tr class="red"><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->Green row : 4.1<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->4.2<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
      <!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->4.3<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--></tr><!--[/ELEMENT('.red')]-->
  <!--[ELEMENT('.red')]--><tr class="red"><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->Green row : 5.1<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->5.2<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
      <!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->5.3<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--></tr><!--[/ELEMENT('.red')]-->
  <!--[ELEMENT('.red')]--><tr class="red"><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->Green row : 6.1<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->6.2<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
      <!--[/TEXT('.red')]--><td><!--[TEXT('.red')]-->6.3<!--[/TEXT('.red')]--></td><!--[TEXT('.red')]-->
<!--[/TEXT('.red')]--></tr><!--[/ELEMENT('.red')]-->
</tbody></table>
<p></p>
<table class="t2" border="1">
  <tbody><tr>
<td>1.1</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>1.3</td>
      <td>1.4</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>1.6</td>
      <td>1.7</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
</tr>
  <tr>
<td>2.1</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>2.3</td>
      <td>2.4</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>2.6</td>
      <td>2.7</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
</tr>
  <tr>
<td>3.1</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>3.3</td>
      <td>3.4</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
<td>3.6</td>
      <td>3.7</td>
<!--[ELEMENT('.red')]--><td class="red"><!--[TEXT('.red')]-->green cell<!--[/TEXT('.red')]--></td><!--[/ELEMENT('.red')]-->
</tr>
</tbody></table>
</div>

</body></html>